<?php
	function ThongBaoLoi($thongbao = "")
	{
		echo "<script> alert('".$thongbao."'); </script>";
	}
	
	function ThongBao($thongbao = "")
	{
		echo "<script> alert('".$thongbao."'); </script>";
	}
	
	function KiemTraNgay(&$chuoingay)
	{
		// Input: 22/02/2013
		$arr = explode("/", $chuoingay);
		
		$ngay = (int)$arr[0];
		$thang = (int)$arr[1];
		$nam = (int)$arr[2];
		
		if(checkdate($thang, $ngay, $nam))
		{
			// Output: 2013-02-22
			$chuoingay = "$nam-$thang-$ngay";
			
			return true;
		}
		else
		{
			return false;
		}
	}
	function getAutoID($PhanChu,$PhanSo)
	{
		if($PhanSo < 1000)
		{
			if($PhanSo < 100)
			{
				if($PhanSo < 10)
				$PhanSo = "000".$PhanSo;
			}
			else
			$PhanSo = "00".$PhanSo;
		}
		else
			$PhanSo = "0".$PhanSo;
		return $PhanChu."_".$PhanSo;
	}
	function InNgay($chuoingay)
	{
		// Input: 22/02/2013
		$arr = explode("-", $chuoingay);
		
		$nam = $arr[0];
		$thang = $arr[1];
		$A = $arr[2];
		
		$arr1 = explode(" ", $A);
		$ngay = $arr1[0];
		$time = $arr1[1];
		
		$datetime = $ngay . "/" . $thang . "/" . $nam . ", " . $time;
		
		return $datetime;
	}
	
	function vn2latin($cs, $tolower = false)
	{
		/*Mảng chứa tất cả ký tự có dấu trong Tiếng Việt*/
		$marTViet=array("à","á","ạ","ả","ã","â","ầ","ấ","ậ","ẩ","ẫ","ă",
		"ằ","ắ","ặ","ẳ","ẵ","è","é","ẹ","ẻ","ẽ","ê","ề",
		"ế","ệ","ể","ễ",
		"ì","í","ị","ỉ","ĩ",
		"ò","ó","ọ","ỏ","õ","ô","ồ","ố","ộ","ổ","ỗ","ơ",
		"ờ","ớ","ợ","ở","ỡ",
		"ù","ú","ụ","ủ","ũ","ư","ừ","ứ","ự","ử","ữ",
		"ỳ","ý","ỵ","ỷ","ỹ",
		"đ",
		"À","Á","Ạ","Ả","Ã","Â","Ầ","Ấ","Ậ","Ẩ","Ẫ","Ă",
		"Ằ","Ắ","Ặ","Ẳ","Ẵ",
		"È","É","Ẹ","Ẻ","Ẽ","Ê","Ề","Ế","Ệ","Ể","Ễ",
		"Ì","Í","Ị","Ỉ","Ĩ",
		"Ò","Ó","Ọ","Ỏ","Õ","Ô","Ồ","Ố","Ộ","Ổ","Ỗ","Ơ","Ờ","Ớ","Ợ","Ở","Ỡ",
		"Ù","Ú","Ụ","Ủ","Ũ","Ư","Ừ","Ứ","Ự","Ử","Ữ",
		"Ỳ","Ý","Ỵ","Ỷ","Ỹ",
		"Đ"," ");
		 
		/*Mảng chứa tất cả ký tự không dấu tương ứng với mảng $marTViet bên trên*/
		$marKoDau=array("a","a","a","a","a","a","a","a","a","a","a",
		"a","a","a","a","a","a",
		"e","e","e","e","e","e","e","e","e","e","e",
		"i","i","i","i","i",
		"o","o","o","o","o","o","o","o","o","o","o","o",
		"o","o","o","o","o",
		"u","u","u","u","u","u","u","u","u","u","u",
		"y","y","y","y","y",
		"d",
		"A","A","A","A","A","A","A","A","A","A","A","A",
		"A","A","A","A","A",
		"E","E","E","E","E","E","E","E","E","E","E",
		"I","I","I","I","I",
		"O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O",
		"U","U","U","U","U","U","U","U","U","U","U",
		"Y","Y","Y","Y","Y",
		"D","-");
		 
		if ($tolower) {
			return strtolower(str_replace($marTViet,$marKoDau,$cs));
		}
	 
			return str_replace($marTViet,$marKoDau,$cs);
	 
	}
	function DTBMH_HK($diem1,$diem2,$diem3)
	{
		return ($diem1+($diem2*2)+($diem3*3))/(float)6;
	}
	function DTBMH_CN($diemTB1,$diemTB2)
	{
		return ($diemTB1+($diemTB2*2))/(float)3;
	}
	
	function LoaiGioi($MaHocSinh, $NamHoc, $HocKy)
	{
		$diemhk = new diemhkbs();
		$diemhk->MaHocSinh = $MaHocSinh;
		$diemhk->HocKy = $HocKy;
		$diemhk->NamHoc = $NamHoc;
		$ds = $diemhk->GetList();
		$dem = ($ds == false ? 0 : count($ds));
		$kt = true;
		for($i = 0; $i < $dem; $i++)
		{
			if($ds[$i]['DTB_HK'] < 6.5)
			{
				$kt = false;
				break;
			}
		}
		return $kt;
	}
	
	function LoaiKha($MaHocSinh, $NamHoc, $HocKy)
	{
		$diemhk = new diemhkbs();
		$diemhk->MaHocSinh = $MaHocSinh;
		$diemhk->HocKy = $HocKy;
		$diemhk->NamHoc = $NamHoc;
		$ds = $diemhk->GetList();
		$dem = ($ds == false ? 0 : count($ds));
		$kt = true;
		for($i = 0; $i < $dem; $i++)
		{
			if($ds[$i]['DTB_HK'] < 5)
			{
				$kt =false;
				break;
			}
		}
		return $kt;
	}
	
	function LoaiTB($MaHocSinh, $NamHoc, $HocKy)
	{
		$diemhk = new diemhkbs();
		$diemhk->MaHocSinh = $MaHocSinh;
		$diemhk->HocKy = $HocKy;
		$diemhk->NamHoc = $NamHoc;
		$ds = $diemhk->GetList();
		$dem = ($ds == false ? 0 : count($ds));
		$kt = true;
		for($i = 0; $i < $dem; $i++)
		{
			if($ds[$i]['DTB_HK'] < 3.5)
			{
				$kt =false;
				break;
			}
		}
		return $kt;
	}
	
	function LoaiYeu($MaHocSinh, $NamHoc, $HocKy)
	{
		$diemhk = new diemhkbs();
		$diemhk->MaHocSinh = $MaHocSinh;
		$diemhk->HocKy = $HocKy;
		$diemhk->NamHoc = $NamHoc;
		$ds = $diemhk->GetList();
		$dem = ($ds == false ? 0 : count($ds));
		$kt = true;
		for($i = 0; $i < $dem; $i++)
		{
			if($ds[$i]['DTB_HK'] < 2)
			{
				$kt =false;
				break;
			}
		}
		return $kt;
	}
	function XetHanhKiem($HanhKiem1,$HanhKiem2)
	{
		return ($HanhKiem1+$HanhKiem2+1)/2;
	}
	function DTB_HK($MaHocSinh, $NamHoc, $HocKy)
	{
		$tu =0; $mau = 0;
		$diemhk = new diemhkbs();
		$diemhk->MaHocSinh = $MaHocSinh;
		$diemhk->HocKy = $HocKy;
		$diemhk->NamHoc = $NamHoc;
		$ds = $diemhk->GetList();
		$dem = ($ds == false ? 0 : count($ds));
		for($i = 0; $i < $dem; $i++)
		{
			if($ds[$i]['ThiLai'] == 0)
				$tu+=($ds[$i]['DTB_HK']*$ds[$i]['HeSo']);
			else
			{
				$diemthilai = new diemthilaibs();
				$diemthilai->MaHocSinh = $ds[$i]['MaHocSinh'];
				$diemthilai->HocKy = $ds[$i]['HocKy'];
				$diemthilai->NamHoc = $ds[$i]['NamHoc'];
				$diemthilai->MaMonHoc = $ds[$i]['MaMonHoc'];
				$dsthilai = $diemthilai->GetList();
				$tu+=($dsthilai[0]['DiemTB']*$ds[$i]['HeSo']);
			}
			$mau+=$ds[$i]['HeSo'];
		}
		return $tu/(float)$mau;
	}

?>